//
//  User.swift
//  FeastBooking
//
//  Created by Imon on 2017/9/24.
//  Copyright © 2017年 Imon. All rights reserved.
//

import Foundation
import ObjectMapper

class UserProfile: Response {
    
    var avatar: String?
    var email: String?
    var phone: String?
    var userId: Int?
    var username: String?
    
    required init?(map: Map) {
        super.init(map: map)
    }
    
    override func mapping(map: Map) {
        super.mapping(map: map)
        avatar <- map["avatar"]
        email <- map["email"]
        phone <- map["phone"]
        userId <- map["userId"]
        username <- map["username"]
    }
}

class User: Response {
    
    var username: String?
    var email: String?
    var role: String?
    var id: Int?
    
    required init?(map: Map){
        super.init(map: map)
    }
    
    override func mapping(map: Map) {
        super.mapping(map: map)
        id <- map["id"]
        username <- map["username"]
        email <- map["email"]
        role <- map["role"]
    }
}

class UserRegisterResponse: Response {
    
    var success: Bool?
    var data: Any?
    
    required init?(map: Map) {
        super.init(map: map)
    }
    
    override func mapping(map: Map) {
        super.mapping(map: map)
        success <- map["success"]
        if success! {
            var data: UserRegisterResponseData? = nil
            data <- map["data"]
            self.data = data
        } else {
            var data: String? = nil
            data <- map["data"]
            self.data = data
        }
    }
}

class ChangePWResponse: Response {
    
    var success: Bool?
    var data: String?
    
    required init?(map: Map) {
        super.init(map: map)
    }
    
    override func mapping(map: Map) {
        super.mapping(map: map)
        success <- map["success"]
        data <- map["data"]
    }
}

class UserRegisterResponseData: Mappable {
    
    var id: Int?
    var token: String?
    
    required init?(map: Map) {
        
    }
    
    func mapping(map: Map) {
        token <- map["token"]
        id <- map["id"]
    }
}

class UserTokenResponse: Response {
    
    var token: String?
    var user: User?
    
    required init?(map: Map){
        super.init(map: map)
    }
    
    override func mapping(map: Map) {
        super.mapping(map: map)
        token <- map["token"]
        user <- map["user"]        
    }
}
